#include		<stdio.h>
#include		<avr/io.h>
#include		"lcd.h"
#include		"eeprom.h"

#define	GET_NOW	(PIND & 1<<PD0 ? 1 : 0)

int	main(void)
{		
	unsigned	int	ee_addr = 0;
	unsigned	char	ee_wdata = 0, ee_rdata;
	unsigned	char	now, prev;
	char lcd_string[2][MAX_LCD_STRING];
	
	PORTD |= 1<<PD0;
	
	LCD_init();

	sprintf(lcd_string[0], "< EEPROM TEST > ");
	sprintf(lcd_string[1], "   W/R Verify   ");

	LCD_str_write(0, 0, lcd_string[0]);
	LCD_str_write(1, 0, lcd_string[1]);
	
	while(1){
		for(prev = now = GET_NOW; !(now==1 && prev==0); now=GET_NOW)
			prev = now;

		eeprom_write_byte(ee_addr, ee_wdata);
		ee_rdata = eeprom_read_byte(ee_addr);
		
		sprintf(lcd_string[0], "[EEPROM ADDR]%3X", ee_addr);
		sprintf(lcd_string[1], "[WR]%2X [RD]%2X", ee_wdata, ee_rdata);

		LCD_str_write(0, 0, lcd_string[0]);
		LCD_str_write(1, 0, lcd_string[1]);

		ee_addr++;
		ee_wdata--;
	}
	return 0;
}
